package cn.edu.sdjzu.xg.eagle.service;

import cn.edu.sdjzu.xg.eagle.dao.UserDaoImpl;
import cn.edu.sdjzu.xg.eagle.dao.UserDaoInterface;
import cn.edu.sdjzu.xg.eagle.entity.User;
import cn.edu.sdjzu.xg.eagle.factory.DaoFactory;
import cn.edu.sdjzu.xg.eagle.util.JdbcHelper;

import java.sql.Connection;
import java.sql.SQLException;

public class UserServiceImpl implements UserServiceInterface{
    private UserDaoInterface userDao = DaoFactory.getDao(UserDaoImpl.class,"UserDaoImpl");

    public UserServiceImpl() {} // 必须存在

    @Override
    public void login(User userToLogin) throws SQLException {
        // 使用 try-with-resources 自动管理连接
        try (Connection connection = JdbcHelper.getConn()) {
            userDao.login(connection, userToLogin);
        }
    }
}
